<?php

namespace App\Http\Controllers;


use App\Chest;
use App\Grip;
use App\Order;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class OrderController extends Controller
{
    public function index()
    {
        $user = Auth::user();
        $orders = $user->order()->where(['goods_type'=>'App\Package'])->get();
        return view('user.order', compact('user', 'orders'));
    }
    //押金下订单
    public function generateOrder(Request $request)
    {
        $user = Auth::user();
        $gripId = $request->get('gripId');
        $grip  = Grip::where(['id'=>$gripId])->first();
        $chest = $grip->chest;
        $package = 'service';
        $addition = '';
        $order = Order::generate($user, $chest['deposit'], 0, $package, $addition);
        return route('counter.wechat', ['order_no' => $order->order_no]);
    }

}
